<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of categorias_model
 *
 * @author Lucas Pinheiro
 */
class Pedidos_model extends MY_Model {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->banco = null;
        $this->tabela = 'pedidos_tbl';
        $this->apelido = 'pe';
    }

    public function consultar() {
        $this->db->select('*, sum(pi.valor_total) as valor_total');
        $this->db->group_by('pe.id_pedidos');
        $this->db->join(($this->banco != null ? $this->banco . '.' : '') . 'clientes_tbl as cl', 'pe.id_clientes = cl.id_clientes', 'INNER');
        $this->db->join(($this->banco != null ? $this->banco . '.' : '') . 'pedidos_itens_tbl as pi', 'pe.id_pedidos = pi.id_pedidos', 'INNER');
        $query = $this->db->get(($this->banco != null ? $this->banco . '.' : '') . $this->tabela . ' as ' . $this->apelido);
        if ($query->num_rows() > 0) {
            return $query->result();
        } else {
            return NULL;
        }
    }

}